home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / yase.arc / VSCREEN.ASM < prev    next >
Assembly Source File  |  1986-12-13  |  4KB  |  120 lines

  1. ******************************************************************
  2. * COPYRIGHT (C) 1986 by Donald Krantz and James Stanley
  3. * - Note: This is a real, live, actual, registered copyright,
  4. *   and should be treated as such. This source code is from
  5. *   the book "68000 Assembly Language", Krantz and Stanley,
  6. *   Addison-Wesley Publishing Company, Reading, MA, 1986.
  7. *   Permission granted by the authors for non-commercial use
  8. *   in programs released to the public domain, as long as this
  9. *   copyright notice remains attached and visible.
  10. *
  11. *****************************************************************
  12. * Virtual Screen - Maintains a virtual interface to a slow 
  13. * CRT output device. Scrolling not supported.
  14.  
  15. lines    equ    24        * lines on actual screen
  16. cols    equ    80        * columns on actual screen
  17.     
  18.     xdef    cls,cursor,putc,sync_curs,v_scrn
  19.     xref    _crt_cls,_crt_put,_crt_cursor    
  20.  
  21. * CLS
  22. * Clears the CRT. No parameters.
  23. *
  24. * CURSOR
  25. * Sets the cursor to an (X,Y) position. Calling sequence: push
  26. * Y, then X. X and Y are binary, zero-based, word length.
  27. * PUTC
  28. * Outputs a character to the display. Calling sequence: push
  29. * the character to be output in the low byte os a word.
  30. *
  31. * SYNC_CURS
  32. * Syncs the actual CRT cursor the the virtual CRT cursor, as it
  33. * usually isn't where it ought to be, especially when doing
  34. * inputs. No parameters.
  35. *****************************************************************
  36. cls:
  37.     movem.l    a0/d0/d1,-(a7)    * save user's registers
  38.     move.w    #(lines*cols),d0  Number of chars to blank
  39.     lsr.w    #1,d0        * Divide by to for word store
  40.     move.w    #'  ',d1    * we'll use register for speed
  41.     move.l    #v_scrn,a0    * our memory copy
  42.     bra    loop_test    * Go do loop test
  43. loop:
  44.     move.w    d1,(a0)+    * store two blanks at a crack
  45. loop_test:
  46.     dbra    d0,loop        * loop thru all memory    
  47.     bsr    _crt_cls    * clear physical screen
  48.     move.w    #1,sync        * set sync flag true
  49.     move.l    #v_scrn,my_curs    * sync my cursor
  50.     clr.l    -(a7)        * put two zero words on stack
  51.     bsr    _crt_cursor    * sync user's cursor
  52.     addq.l    #4,a7        * adjust stack
  53.     clr.w    his_lin        * clear user's line counter
  54.     clr.w    his_col        * clear user's column counter
  55.     movem.l    (a7)+,a0/d0/d1    * restore user's registers
  56.     rts
  57. *****************************************************************
  58. * Sets cursor to arbitrary screen location
  59. cursor:
  60.     clr.w    sync        * set sync flag false    
  61.     move.w    4(a7),his_col    * save crt screen X position
  62.     move.w    6(a7),his_lin    * save crt screen Y position
  63.     move.l    d0,-(a7)    * save D0 across calculation
  64.     clr.l    d0        * start with clean register
  65.     move.w    10(a7),d0    * get new line number
  66.     mulu    #cols,d0    * multiply by cols to get offset
  67.     add.w    8(a7),d0    * add in column offset
  68.     add.l    #v_scrn,d0    * add base to get address
  69.     move.l    d0,my_curs    * now we should be at same spot
  70.     move.l    (a7)+,d0    * restore d0
  71.     rts
  72. *****************************************************************
  73. * Output character to screen if necessary
  74. putc:
  75.     link    a6,#0        * freeze stack frame
  76.     movem.l    d0/a0,-(a7)    * save user's stuff
  77.     move.w    8(a6),d0    * get char to output
  78.     move.l    my_curs,a0    * get my screen address
  79.     cmp.b    (a0),d0        * are they the same?
  80.     beq    no_put        * jump if yes
  81.     move.b    d0,(a0)        * Store char in virtual screen
  82.     tst.w    sync        * are we synced?
  83.     bne    synced        * jumps if synced
  84.     bsr    sync_curs    * sync cursors
  85. synced:
  86.     move.w    8(a6),-(a7)    * push his character
  87.     bsr    _crt_put    * send to crt
  88.     addq.l    #2,a7        * adjust stack
  89.     bra    did_put        * set other vars
  90. no_put:
  91.     clr.w    sync        * show out of sync
  92. did_put:
  93.     addq.l     #1,my_curs    * increment my cursor
  94.     addq.w    #1,his_col    * and his column count
  95.     movem.l    (a7)+,d0/a0    * restore user's stuff
  96.     unlk    a6
  97.     rts
  98. *****************************************************************
  99. * SYNC_CURS - Syncs crt cursor to virtual cursor
  100. sync_curs:
  101.     move.w    d0,-(a7)    * Saving char across put call
  102.     move.w    his_lin,-(a7)    * Push Y address
  103.     move.w    his_col,-(a7)    * Push X address
  104.     bsr    _crt_cursor    * set actual cursor
  105.     addq.l    #4,a7        * adjust stack
  106.     move.w    #1,sync        * show synced
  107.     move.w    (a7)+,d0    * restore character
  108.     rts
  109. *****************************************************************
  110.     bss
  111. sync:    ds.w    1        * actual display synced flag
  112. v_scrn:    ds.b    (lines*cols)    * virtual screen memory
  113. my_curs:ds.l    1        * virtual screen cursor location
  114. his_lin:ds.w    1        * actual screen line number
  115. his_col:ds.w    1        * actual screen column number
  116.  
  117.     end
  118.